/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhnb
 * Date: 2011-8-10 下午03:17:32
 */
package ccxe.util.db;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import ccxe.util.properties.DocDemoJxlProperties;

/**
 * 提供数据库连接（jdbc方式）
 * 
 * @author zhnb
 * 
 */
public class DBManager implements Serializable {

    private static final long serialVersionUID = -5565287391657398474L;

    /**
     * 获取数据库连接
     * 
     * @return
     */
    public static Connection getConnection() {

        Connection conn = null;

        try {
            // 加载驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");

            // 读取连接配置
            Properties properties = DocDemoJxlProperties.getProperties();
            String dbhost = properties.getProperty("dbhost");
            String dbport = properties.getProperty("dbport");
            String dbname = properties.getProperty("dbname");
            String dbuser = properties.getProperty("dbuser");
            String dbpwd = properties.getProperty("dbpwd");

            // 拼装连接URL
            StringBuffer connUrl = new StringBuffer();
            connUrl.append("jdbc:oracle:thin:@");
            connUrl.append(dbhost);
            connUrl.append(":");
            connUrl.append(dbport);
            connUrl.append(":");
            connUrl.append(dbname);

            // 获取连接
            conn = DriverManager.getConnection(connUrl.toString(), dbuser,
                    dbpwd);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return conn;
    }
}
